package com.itheima.dao.impl;

import com.itheima.dao.ITeacherDao;
import com.itheima.domain.Teacher;
import com.itheima.domain.Teacher;

import java.util.ArrayList;

public class TeacherDaoImpl implements ITeacherDao {
    private static ArrayList<Teacher> list= new ArrayList<>();
    static {
        Teacher teacher1 = new Teacher("0001", "张三", 23, "9999");
        Teacher teacher2 = new Teacher("0002", "李四", 24, "8888");
        Teacher teacher3 = new Teacher("0003", "王五", 25, "7777");
        Teacher teacher4 = new Teacher("0004", "赵六", 26, "6666");
        list.add(teacher1);
        list.add(teacher2);
        list.add(teacher3);
        list.add(teacher4);

    }
    @Override
    public void addTeacher(Teacher Teacher) {
        list.add(Teacher);
    }

    @Override
    public void deleteTeacher(String sid) {
        int index = getIndex(sid);
        list.remove(index);
    }

    @Override
    public void updateTeacher(String sid, Teacher newStu) {
        int index = getIndex(sid);
        list.set(index,newStu);
    }

    @Override
    public ArrayList<Teacher> findAllTeachers() {
        return list;
    }

    @Override
    public int getIndex(String sid) {
        for (int i = 0; i < list.size(); i++) {
            Teacher Teacher = list.get(i);
            if(Teacher.getSid().equals(sid)){
                return i;
            }
        }
        return -1;
    }
}
